package com.swift.authority.common.util;

import java.util.*;

/**
 * @author Administrator
 * @version 1.0
 * @description 字符串工具类
 * @date 2022/06/25  12:22
 */
public class StringUtil {
    /**
     * 字符串判空
     *
     * @param str 入参字符
     * @return Boolean
     */
    public static boolean isEmpty(final String str) {
        return (str == null) || (str.length() == 0);
    }

    /**
     * 判断是否不为空
     *
     * @param str 入参字符
     * @return boolean
     */
    public static boolean isNotEmpty(final String str) {
        return !isEmpty(str);
    }

    /**
     * 判断是否空白
     *
     * @param str
     * @return
     */
    public static boolean isBlank(final String str) {
        int strLen;
        if ((str == null) || ((strLen = str.length()) == 0)) {
            return true;
        }
        for (int i = 0; i < strLen; i++) {
            if (!Character.isWhitespace(str.charAt(i))) {
                return false;
            }
        }
        return true;
    }

    /**
     * 判断是否不是空白
     *
     * @param str
     * @return
     */
    public static boolean isNotBlank(final String str) {
        return !isBlank(str);
    }

    /**
     * 将标题与列数据对齐存放：格式化 标题与列数据加工的字符
     *
     * @param keyMap 标题
     * @param str    标题与列数据加工的字符
     * @return 处理结果
     */
    public static Map<Object,Object> formatToMap(Map<Object,Object> keyMap,String str){
        Map<Object,Object> returnMap = new HashMap<>();
        Iterator<Object> iterator = keyMap.keySet().iterator();
        while (iterator.hasNext()){
            Object key = iterator.next();
            String value = null;
            if(key == null){
                return null;
            }

            value = keyMap.get(key).toString();
            if(value ==null){
                return null;
            }

            if(str == null){
                return null;
            }

            List<String> valueList = new ArrayList<>();
            String[] data = str.split(":");
            for (int i = 0; i < data.length; i++) {
                if(data[i].endsWith("."+value)){
                    valueList.add(data[i].replace("."+ value,""));
                    returnMap.put(value,valueList);
                }
            }

        }
        return returnMap;
    }
}
